<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  String _id=request.getParameter("_");
  request.setAttribute("now",new Date());
%>

<div class="row">
    <div class="col-lg-12">
        <div class="panel">
            <div class="panel-heading">
                <h3 class="panel-title">发文申请表</h3>
            </div>

            <div style="margin: 10px">

                <!-- Nav tabs -->
                <ul class="nav nav-tabs">
                    <li class="active"><a href="#bsc-tab-1" data-toggle="tab">发文申请表</a></li>
                    <c:if test="${outfile.numStatus==1}">
                        <li><a href="#bsc-tab-2" data-toggle="tab">发文修订</a></li>
                    </c:if>
                </ul>

                <!-- Tabs Content -->
                <div class="tab-content">

                    <div class="tab-pane pad-btm fade in active" id="bsc-tab-1">
                        <!-- BASIC FORM ELEMENTS -->
                        <!--===================================================-->
                        <form id="form_outfile_input" class="panel-body form-horizontal form-padding">
                            <input type="hidden" name="keyId" id="keyId" value="${outfile.id}" />
                            <input type="hidden" name="updateUnid" id="updateUnid" value="${outfile.updateUnid}" />

                            <div class="form-group">
                                <label class="col-md-2 control-label">发文类别<i class="fa fa-asterisk txt-color-red"></i></label>
                                <div class="col-md-6">
                                    <input type="text" id="dictItem" name="dictItem" class="form-control" value="${outfile.dictItem.name}" disabled>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-2 control-label">发文标题<i class="fa fa-asterisk txt-color-red"></i></label>
                                <div class="col-md-6">
                                    <input type="text" id="name" name="name" class="form-control" disabled value="${outfile.name}">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-2 control-label">文件编号<i class="fa fa-asterisk txt-color-red"></i></label>
                                <div class="col-md-6">
                                    <input type="text" id="fileNo" name="fileNo" class="form-control" disabled value="${outfile.fileNo}">
                                </div>
                            </div>

                            <div class="form-group div-Hidden">
                                <label class="col-md-2 control-label">发文时间<i class="fa fa-asterisk txt-color-red"></i></label>
                                <div class="col-md-6">
                                    <div class="input-group date">
                                        <input type="text" class="form-control" id="datPulished" name="datPulished" disabled
                                               value=<fmt:formatDate pattern="yyyy-MM-dd" value="${outfile.datPulished}" /> >
                                        <span class="input-group-addon"><i class="ti-calendar"></i></span>
                                    </div>
                                </div>
                            </div>


                            <div class="form-group">
                                <label class="col-md-2 control-label">通知对象<i class="fa fa-asterisk txt-color-red"></i>
                                    <span id="noticeTypeSpan" style="display: none">${outfile.noticeType}</span>
                                </label>
                                <div class="col-md-6">
                                    <input type="text" id="noticeType" name="noticeType" class="form-control" disabled>
                                </div>
                            </div>

                            <div class="form-group" id="divNoticeDepts">
                                <label class="col-md-2 control-label">
                                    通知部门
                                    <i class="fa fa-asterisk txt-color-red"></i>
                                </label>
                                <div class="col-md-6">
                                    <input type="text" id="deptNames" name="deptNames" class="form-control" disabled
                                           value="<c:forEach var="item" items="${outfile.noticeDepartments}" varStatus="status">${item.name}<c:if test="${!status.last}">,</c:if></c:forEach>">
                                </div>
                            </div>

                            <div class="form-group" id="divNoticeUsers">
                                <label class="col-md-2 control-label">
                                    通知个人
                                    <i class="fa fa-asterisk txt-color-red"></i>
                                </label>
                                <div class="col-md-6">
                                    <input type="text" id="userNames" name="userNames" class="form-control" disabled
                                           value="<c:forEach var="item" items="${outfile.noticeUsers}" varStatus="status">${item.name}<c:if test="${!status.last}">,</c:if></c:forEach>">
                                </div>
                            </div>


                            <div class="form-group">
                                <label class="col-md-2 control-label">
                                    会签对象
                                    <i class="fa fa-asterisk txt-color-red"></i>
                                </label>
                                <div class="col-md-6">
                                    <input type="text" id="viewerNames" name="viewerNames" class="form-control" disabled
                                           value="<c:forEach var="item" items="${outfile.viewers}" varStatus="status">${item.name}<c:if test="${!status.last}">,</c:if></c:forEach>">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-2 control-label">相关附件<i class="fa fa-asterisk txt-color-red"></i></label>
                                <div class="col-md-6">
                                    <input name="hiddenFiles" id="hiddenFilesAttachment" type="hidden" disabled value="${outfile.fileAttachment}">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-2 control-label">提交人</label>
                                <div class="col-md-2">
                                    <p class="form-control-static">${outfile.creater.name}</p>
                                </div>
                                <label class="col-md-2 control-label">提交日期</label>
                                <div class="col-md-2">
                                    <p class="form-control-static"><fmt:formatDate pattern="yyyy-MM-dd" value="${outfile.dateApply}" /></p>
                                </div>
                            </div>
                        </form>

                        <!--===================================================-->
                        <!-- END BASIC FORM ELEMENTS -->

                        <div class="panel-footer">
                            <a class="btn btn-default" id="apply-re-common" href="javascript:void(0)">
                                <i class="fa fa-lg fa-mail-reply"></i> 返回视图
                            </a>
                            <c:if test="${outfile.numStatus==0 && user.id==outfile.creater.id}">
                                <a class="btn btn-warning" key="ajax_outfile_edit" href="javascript:void(0);"><i class="fa fa-lg fa-edit"></i> 编辑表单 </a>
                            </c:if>
                        </div>
                    </div>

                    <div class="tab-pane fade" id="bsc-tab-2">
                        <div class="table-responsive" style="min-height: 530px;margin: 10px">
                            <table id="outfile_history_table"></table>
                            <div id="outfile_history_page"></div>
                        </div>
                    </div>

                </div>
            </div>

        </div>
    </div>
</div>

<script>

    // 附件显示
    readLoad({
        objId:"hiddenFilesAttachment",
        entityName:"fileAttachment",
        sourceId:"hiddenFilesAttachment"
    });

    //返回视图
    $("#apply-re-common").click(returnToHashUrl);

    //编辑
    $("a[key='ajax_outfile_edit']").unbind("click").bind("click",function(){
        loadURL("<%=path%>/activiti/outfile/edit/"+$("#keyId").val()+"/n",$('#page-content'));
    });

    // 加载完成后执行
    $(function(){
        var type = $("#noticeTypeSpan").text();
        if (type=="1") {
            $("#noticeType").val("部门");
            $("#divNoticeDepts").show();
            $("#divNoticeUsers").hide();
        } else if(type=="2"){
            $("#noticeType").val("个人");
            $("#divNoticeDepts").hide();
            $("#divNoticeUsers").show();
        } else {
            $("#noticeType").val("全体员工");
            $("#divNoticeDepts").hide();
            $("#divNoticeUsers").hide();
        }

        init_grid_outfile_history();
    })

    function init_grid_outfile_history() {
        __init_jqgrid('outfile_history_table', 'outfile_history_page',
            '<%=path%>/activiti/outfile/list?updateUnid='+$("#updateUnid").val(),
            ['发文类别', '文件编号', '发文标题', '发文时间', '修订次数','文档状态', '操作', 'id'],
            [
                {name: 'dictItemName', index: 'dictItemName', width: 50, sortable: true, search: false},
                {name: 'fileNo', index: 'fileNo', width: 50, sortable: true, search: false},
                {name: 'name', index: 'name', width: 200, sortable: false, stype: 'text', searchoptions: {sopt: ['cn']}},
                {name: 'datPulished', index: 'datPulished', width: 50, sortable: false, search: false},
                {name: 'numRevise', index: 'numRevise', width: 50, sortable: false, search: false},
                {name: 'txtStatus', index: 'txtStatus', width: 50, sortable: false, search: false},
                {name: 'act', index: 'act', width: 150, fixed: true, sortable: false, search: false, formatter: actFormat},
                {name: 'id', index: 'id', width: 100, key: true, hidden: true, hidedlg: true}
            ],
            true,
            {
                autowidth: false,
                width: 1400,
                height: 500,
                postData: {catalog: 0x01}
            }
        );

    }

    function actFormat(cellvalue, options, rowObject){
        var id = rowObject.id;
        cellvalue = '<button class="btn btn-white btn-sm" data-original-title="查看" onclick="fn_outfile_read(\'' + id + '\');"><i class="fa fa-eye"> </i> 查看</button> ';
        return cellvalue;
    }

    function fn_outfile_read(id) {
        var url = '<%=path%>/activiti/outfile/readhistory/'+id;
        __open_dialog_form_read('发文申请表', url);
    }
</script>
